﻿using System;

namespace LightSwitchApplication
{
    public class Utils
    {
        public static string SimpleEncoder(string plain)
        {
            if (!string.IsNullOrEmpty(plain))
            {
                byte[] byt = System.Text.Encoding.UTF8.GetBytes(plain);
                // convert the byte array to a Base64 string
                plain = Convert.ToBase64String(byt);
            }
            else
            {
                plain = string.Empty;
            }
            return plain;
        }

        public static string SimpleDecoder(string encoded, string terminator="")
        {
            if (!string.IsNullOrEmpty(encoded))
            {
                byte[] b = Convert.FromBase64String(encoded.Replace(' ', '+') + terminator); // + "=="
                string strOriginal = System.Text.Encoding.UTF8.GetString(b, 0, b.Length);
                return strOriginal;
            }
            else
            {
                return string.Empty;
            }
        }
    }
}
